const ua = window.navigator.userAgent;
import nativeSchema from './tool-native-schema';
export function handleOpenApp(arg) { 
	let hasClickOnce;
	if (!hasClickOnce) {
		hasClickOnce = true;
		openApp(arg);
	}
	setTimeout(() => {
		hasClickOnce = false;
	}, 2000);
}

function openApp(arg) {
	let params = []
	for (let prop in arg.props) { 
		params.push(`${prop}=${encodeURIComponent(arg.props[prop])}`)
	}
	nativeSchema.loadSchema({
		// 某个schema协议，例如login,
		schema: `/${arg.routerAddr}?${params.join('&')}`,
		// schema头协议，
		protocal: "lovelorn://react-native",
		// 发起唤醒请求后，会等待loadWaiting时间，超时则跳转到failUrl，默认3000ms
		loadWaiting: 3000,
		// 唤起失败时的跳转链接，默认跳转到应用商店下载页
		failUrl: ua.indexOf('Android') > -1 ? "https://sj.qq.com/myapp/detail.htm?apkName=com.yryz.lovelorn" : 'itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1438503085',
		// failUrl: window.location.href = window.location.origin + '/static/page/download.html'
	});
}
